/*
 * @Author: 来自火星的码农 15122322+heyzhi@user.noreply.gitee.com
 * @Date: 2025-10-11 19:40:33
 * @LastEditors: 来自火星的码农 15122322+heyzhi@user.noreply.gitee.com
 * @LastEditTime: 2025-10-30 15:24:06
 * @FilePath: /GateServer/src/mysql/mysqlmgr.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include "mysqlmgr.h"
#include <string>
#include "../util/logger.h"
namespace Yizhi {
    int MysqlMgr::RegUser(const std::string &username,const std::string &email,const std::string &Psw){
        int res=m_dao.RegUser(username,email,Psw);
        return res;
    }
    bool MysqlMgr::ExistUser(std::string username,std::string email){
        auto res=m_dao.findUser(username, email);
        return res;
    }
    int MysqlMgr::RsetPsw(std::string username,std::string email,std::string psw){
        auto res=m_dao.ResetPsw(username, email, psw);
        return res;
    }
    bool MysqlMgr::finduserbyemail(const std::string&email){
        auto res=m_dao.findUserbyeamil(email);
        return res;
    }

    bool MysqlMgr::login(User& user){
        auto res=m_dao.login(user.getUsername(),user.getPassword());
        if(res!=-1){
            LOG_DEBUG(res);
            user.setUid(res);
            auto n_user=m_dao.getUserbyId(res);
            user.setEmail(n_user.getEmail());
            return true;
        }
        return false;
    }
}